﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using BigEgg.UnitTesting;

namespace UnitTestDemo.SimpleDemo.Test
{
    [TestClass]
    public class PersonTest
    {
        [TestMethod]
        public void GeneralPersonTest()
        {
            Person person = new Person("BigEgg");
            Assert.AreEqual("BigEgg", person.Name);
            Assert.AreEqual(0, person.Contacts.Count);
            Assert.AreEqual(100, person.Energy);

            person.Gender = Gender.Male;
            person.Age = 26;
            person.Contacts.Add(new ContactInfo()
                {
                    Type = "Uri",
                    Value = @"https://unittestdemo.codeplex.com/"
                });

            Assert.AreEqual(Gender.Male, person.Gender);
            Assert.AreEqual(26, person.Age);
            Assert.AreEqual(1, person.Contacts.Count);
        }

        [TestMethod]
        public void ConstructorTest()
        {
            AssertHelper.ExpectedException<ArgumentException>(() => new Person(""));
            AssertHelper.ExpectedException<ArgumentException>(() => new Person(null));
        }

        [TestMethod]
        [ExpectedException(typeof(ArgumentException))]
        public void ConstructorTest1()
        {
            Person person = new Person("");
        }

        [TestMethod]
        [ExpectedException(typeof(ArgumentException))]
        public void ConstructorTest2()
        {
            Person person = new Person(null);
        }

        [TestMethod]
        public void RunTest()
        {
            Person person = new Person("BigEgg");

            Assert.AreEqual(100, person.Energy);
            person.Run();
            Assert.AreEqual(50, person.Energy);

            person.Run();
            Assert.AreEqual(0, person.Energy);

            AssertHelper.ExpectedException<NotSupportedException>(() => person.Run());
        }

        [TestMethod]
        public void EatTest()
        {
            Person person = new Person("BigEgg");

            Assert.AreEqual(100, person.Energy);
            person.Eat();
            Assert.AreEqual(70, person.Energy);
            person.Eat();
            person.Eat();
            Assert.AreEqual(10, person.Energy);

            AssertHelper.ExpectedException<NotSupportedException>(() => person.Eat());
        }

        [TestMethod]
        public void SleepTest()
        {
            Person person = new Person("BigEgg");

            person.Run();
            person.Eat();
            Assert.IsTrue(100 > person.Energy);

            person.Sleep();
            Assert.AreEqual(100, person.Energy);
        }
    }
}
